<?php
class OrderAction extends CommonAction{
	
	public function index(){

		$orderModel = D("Order");

		import("@.ORG.Page"); //导入分页类
		$count = $orderModel->relation(true)->where("member_id = " . $_SESSION[self::GLOBAL_SESSION_USER_KEY]["id"])->count();    //计算总数
// 		$p = new Page ( $count, self::DEFULT_LIMIT_SIZE );
		$p = new Page ( $count, 3 );
		if(isset($condition)){
			$orders = $orderModel->where("member_id = " . $_SESSION[self::GLOBAL_SESSION_USER_KEY]["id"])->order("create_time desc")->select();
		}else{
			$orders=$orderModel->where("member_id = " . $_SESSION[self::GLOBAL_SESSION_USER_KEY]["id"])->limit($p->firstRow.','.$p->listRows)->order('create_time desc')->select();
		}
		
		if(empty($orders)){
			$this->assign("order_msg","Sorry,No Found This Order");
		}
		
		$p->setConfig('header',' results ');
		$p->setConfig('prev',"<");
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$page = $p->show ();
		$this->assign("condForm",$condForm);
		$this->assign( "page", $page );
		$this->assign ( "orders", $orders );
		
		$this->getAllCategories();
		
		$this->display();
	}
	
	public function view(){
		$order_no = $_GET["order_no"];
		
		$this->getAllCategories();
		
		if(empty($order_no)){
			$this->assign("order_msg","Sorry,No Found This Order");
			$this->display();
		}
		
		$orders = D("Order")->relation(true)->where("order_no='" . $order_no . "'")->select();
		
		if(empty($orders)){
			$this->assign("order_msg","Sorry,No Found This Order");
			$this->display();
		}
		
		for($i=0; $i<count($orders[0]["OrderProduct"]); $i++){
			$orderProductSpecResult = D("OrderProduct")->relation(true)->getById($orders[0]["OrderProduct"][$i]["id"]);
			$orders[0]["OrderProduct"][$i] = $orderProductSpecResult;
		}
		
		$this->assign("order", $orders[0]);
		$this->display();
	}
}

?>